﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace MapEditor.Model
{
    public class RectangleFactory
    {
        /// <summary>
        /// Get rectangle of bitmap with default size
        /// </summary>
        /// <param name="Bitmap"></param>
        /// <returns></returns>
        public static System.Windows.Shapes.Rectangle getDefaultRect(Bitmap Bitmap)
        {
            System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle();
            rect.Fill = createBrush(Bitmap);
            rect.Height = Bitmap.Height;
            rect.Width = Bitmap.Width;

            return rect;
        }

        /// <summary>
        /// Get rectangle of bitmap with custom size
        /// </summary>
        /// <param name="Bitmap"></param>
        /// <param name="Width"></param>
        /// <param name="Height"></param>
        /// <returns></returns>
        public static System.Windows.Shapes.Rectangle getCustomRect(Bitmap Bitmap, double Width, double Height)
        {
            System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle();
            rect.Fill = createBrush(Bitmap);
            rect.Height = Height;
            rect.Width = Width;

            return rect;
        }

        /// <summary>
        /// Get image brush from bitmap
        /// </summary>
        /// <param name="bitmap"></param>
        /// <returns></returns>
        public static ImageBrush createBrush(Bitmap bitmap)
        {
            var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(),
                                  IntPtr.Zero,
                                  Int32Rect.Empty,
                                  BitmapSizeOptions.FromEmptyOptions());
            return new ImageBrush(bitmapSource);
        }
    }
}
